﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HigLabo.WindowsAzure.RestService.ServiceManagement
{
    public class Base64Converter
    {
        private static Encoding _DefaultEncoding = Encoding.UTF8;
        public static Encoding DefaultEncoding 
        {
            get { return _DefaultEncoding; }
            set { _DefaultEncoding = value; } 
        }
        public static String To(String value,Encoding enc)
        {
            return Convert.ToBase64String(enc.GetBytes(value));
        }
        public static String From(String value, Encoding enc)
        {
            if (String.IsNullOrEmpty(value))
            {
                return "";
            }
            return enc.GetString(Convert.FromBase64String(value));
        }
        public static String To(String value)
        {
            return To(value, DefaultEncoding);
        }
        public static String From(String value)
        {
            return From(value, DefaultEncoding);
        }
    }
}
